chrome.browserAction.onClicked.addListener(function(tab) {
    var tabId = tab.id;
   // chrome.tabs.executeScript(tabId, {allFrames: true, code: "initPageLoad()"});
    open58();
});


document.addEventListener('DOMContentLoaded', function() {
    document.getElementById("loginbtn").onclick=myopen58;
});


function myopen58()
{

    var u=  document.getElementById("username").value;
    var p=  document.getElementById("password").value;
    var port1 = chrome.runtime.connect({name: "pop"});//通道名称
    port1.postMessage({
        "act":"my","p":p,"u":u
    });
    chrome.tabs.create( { url : 'UserLogin.html', selected : true } ,function(tab) {
        var tabId = tab.id;

  /*  chrome.tabs.sendMessage(tabId,
        {
            "act":"my","p":p,"u":u
        }, function (e) {
            if (chrome.runtime.lastError) {
                console.log(chrome.runtime.lastError.message);
            }
        });*/

        /*var port = chrome.tabs.connect(//建立通道
            tabId,                        {name: "yisheng"}                );
        port.postMessage({
            "act":"my","p":p,"u":u
        });*/
});
}
function open58()
{
    chrome.tabs.create({url:"https://passport.58.com/login/?path=http://nb.58.com"},function(tab) {
        var tabId = tab.id;
        chrome.tabs.executeScript(tabId, {file: "login58.js"}, function () {
            if (chrome.runtime.lastError) {
                console.log(chrome.runtime.lastError.message);
            }
        });
       /* chrome.tabs.executeScript(tabId, {allFrames: true, code: "initPageLoad()"});*/
    })

}

/*

chrome.tabs.onActivated.addListener(function (activeInfo){
    chrome.tabs.get(activeInfo.tabId, function (tab) {
        var tabId = tab.id;
       // chrome.tabs.executeScript(tabId, {allFrames: true, code: "initPageLoad()"});
    });
});*/
